package com.danco.training.zaneuskaya.controller;





import com.danco.training.zaneuskaya.api.MenuController;


import com.danco.training.zaneuskaya.view.Creator;
import com.danco.training.zaneuskaya.view.IOUtil;
import com.danco.training.zaneuskaya.view.Navigator;





public class MenuControllerImpl implements  MenuController{

	

	
	public static final String END_MESSAGE = "Bye";

	public void runMenu() {

	   

		Creator c = new Creator();
		c.createMenu();

		
		
		Navigator n = new Navigator();
        n.setCurrentMenu(c.getMainMenu());
		n.printMenu();
		int index = IOUtil.readInt();
		
		
		while (n.getCurrentMenu().getMenuItemByKey(index).getMenu() != null){
			
			n.getCurrentMenu().getMenuItemByKey(index).doAction();
			n.navigate(index);
			n.printMenu();
			index = IOUtil.readInt();
			if(n.getCurrentMenu().getMenuItemByKey(index).getMenu() == null){
				
				IOUtil.write(END_MESSAGE);
				
				
			}
			
			
			} 
			
	
		
		
		
		
		
		
		

	}

	
}
